package com.kotlin.android.core

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.kotlin.android.ktx.lifecycle.KtxActivityManager

/**
 * 创建者: zl
 * 创建时间: 2020/5/18 9:03 AM
 * 描述:
 */
abstract class BaseActivity : AppCompatActivity() {
    //    private var mPermissionListener: PermissionListener? = null
//    private lateinit var progressDialogFragment: ProgressDialogFragment
    open fun initVariable() {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initVariable()
        /**
         * Activity 管理交给 [KtxActivityManager]
         */
//        ActivityStackManager.addActivity(this)
        ARouter.getInstance().inject(this)
    }


    /**
     * 加载对话框，使用 mtime-ktx Module 下的 ProgressDialogExt 扩展
     * 详细使用参见 [ProgressDialogActivity]
     */
//    fun showProgressDialog(
//        @StringRes message: Int = R.string.loading,
//        isCancelable: Boolean = true
//    ) {
//        if (!this::progressDialogFragment.isInitialized) {
//            progressDialogFragment = ProgressDialogFragment.newInstance()
//        }
//        progressDialogFragment.show(supportFragmentManager, message, isCancelable)
//    }
//
//    fun hideProgressDialog() {
//        if (this::progressDialogFragment.isInitialized && progressDialogFragment.isVisible) {
//            progressDialogFragment.dismiss()
//        }
//    }

    /**
     * 权限申请，使用 PermissionExt 扩展，
     * 详细使用参见 [PermissionVMActivity]
     */
//    /** 权限申请 */
//    fun onRuntimePermissionsAsk(permissions: Array<String>, listener: PermissionListener) {
//        this.mPermissionListener = listener
//        val activity = ActivityStackManager.getTopActivity()
//        val deniedPermissions: MutableList<String> = mutableListOf()
//
//        permissions
//            .filterNot {
//                ContextCompat.checkSelfPermission(
//                    activity!!,
//                    it
//                ) == PackageManager.PERMISSION_GRANTED
//            }
//            .forEach { deniedPermissions.add(it) }
//
//        if (deniedPermissions.isEmpty())
//            mPermissionListener!!.onGranted()
//        else
//            ActivityCompat.requestPermissions(activity!!, deniedPermissions.toTypedArray(), 1)
//    }
//
//    override fun onRequestPermissionsResult(
//        requestCode: Int,
//        permissions: Array<out String>,
//        grantResults: IntArray
//    ) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
//        if (requestCode == 1) {
//            val deniedPermissions: MutableList<String> = mutableListOf()
//            if (grantResults.isNotEmpty()) {
//                for (i in grantResults.indices) {
//                    if (grantResults[i] != PackageManager.PERMISSION_GRANTED)
//                        deniedPermissions.add(permissions[i])
//                }
//
//                if (deniedPermissions.isEmpty())
//                    mPermissionListener?.onGranted()
//                else
//                    mPermissionListener?.onDenied(deniedPermissions)
//            }
//        }
//    }

//    override fun onDestroy() {
//        super.onDestroy()
//        ActivityStackManager.removeActivity(this)
//    }

}